<template>
  <div>
    <h1 class="text-center mt-[100px] mx-auto text-lg">这是my页</h1>
    <div class="w-[500px] m-auto flex justify-around">
      <button class="border" @click="logout">退出登录</button>
      <nuxt-link to="/goods">跳转到goods</nuxt-link>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { mapMutations } from 'vuex'
export default Vue.extend({
  name: 'HomePage',
  methods: {
    ...mapMutations(['SET_TOKEN', 'SET_USERINFO']),
    async logout() {
      const info = (
        await this.$axios(
          'https://mock.mengxuegu.com/mock/65d955a9351bbd02cf339f94/logout'
        )
      ).data
      if (info.code === 200) {
        // 将token保存到vuex中
        this.SET_TOKEN('')
        this.SET_USERINFO(null)
        this.$router.replace('/login')
      }
    },
  },
})
</script>
